package com.meituan.catering.management.product.biz.model.converter;

import com.google.common.collect.Lists;
import com.meituan.catering.management.product.biz.model.ProductAccessoryBO;
import com.meituan.catering.management.product.biz.model.ProductBO;
import com.meituan.catering.management.product.biz.model.ProductDetailBO;
import com.meituan.catering.management.product.biz.model.ProductMethodBO;
import com.meituan.catering.management.product.dao.model.ProductAccessoryDO;
import com.meituan.catering.management.product.dao.model.ProductDO;
import com.meituan.catering.management.product.dao.model.ProductMethodDO;

import java.util.List;
import java.util.Map;

/**
 * @author Believe
 * Date 2022/5/22 17:24
 */
public class ProductDetailBOConverter {
    public static ProductDetailBO toProductDetailBO(ProductBO productBO,
                                                    List<ProductAccessoryBO> accessoryBOList,
                                                    List<ProductMethodBO> methodBOList) {
        ProductDetailBO productDetailBO = new ProductDetailBO();
        productDetailBO.setProductBO(productBO);
        productDetailBO.setAccessoryBOList(accessoryBOList);
        productDetailBO.setMethodBOList(methodBOList);
        return productDetailBO;
    }

    public static List<ProductDetailBO> toProductDetailBOList(Map<Long, List<ProductAccessoryDO>> accessoryMap,
                                                              Map<Long, List<ProductMethodDO>> methodMap,
                                                              List<ProductDO> productDOList) {
        List<ProductDetailBO> detailBOList = Lists.newLinkedList();
        for (ProductDO productDO : productDOList) {
            ProductDetailBO productDetailBO = new ProductDetailBO();
            productDetailBO.setProductBO(ProductBOConverter.toProductBO(productDO));
            productDetailBO.setAccessoryBOList(ProductAccessoryBOConverter.toProductAccessoryBO(accessoryMap.get(productDO.getId())));
            productDetailBO.setMethodBOList(ProductMethodBOConverter.toProductMethodBO(methodMap.get(productDO.getId())));
            detailBOList.add(productDetailBO);
        }
        return detailBOList;
    }
}
